package org.cll.lagou.study.ssm.controller;

import org.cll.lagou.study.ssm.entity.Resume;
import org.cll.lagou.study.ssm.service.ResumeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/6/23 14:06
 */
@Controller
@RequestMapping(value = "/resume")
public class ResumeController {

    private static final Logger logger = LoggerFactory.getLogger(ResumeController.class);

    @Autowired
    @Qualifier("japResumeService")
    private ResumeService resumeService;

    @RequestMapping(value = "/view")
    public String view(){
        logger.info("====== view");
        return "resume/resume-list";
    }

    @RequestMapping(value = "/list")
    public String list(Model model){
        logger.info("====== list");
        List<Resume> resumes = resumeService.selectAll();
        model.addAttribute("list", resumes);
        return "resume/resume-list";
    }

    @RequestMapping(value = "/{id}/toUpdate")
    public String toUpdate(@PathVariable("id") Long id, Model model){
        logger.info("====== toUpdate");
        Resume resume = resumeService.getById(id);
        model.addAttribute("resume", resume);
        return "resume/resume-update";
    }

    @RequestMapping(value = "/update")
    public String update(Model model, Resume resume){
        logger.info("====== update");
        resumeService.updateResume(resume);
        return "redirect:/resume/list";
    }

    @RequestMapping(value = "/{id}/delete")
    public String delete(@PathVariable("id") Long id){
        logger.info("====== delete");
        resumeService.deleteById(id);
        return "redirect:/resume/list";
    }

    @RequestMapping(value = "/toAdd")
    public String toAdd(){
        logger.info("====== toAdd");
        return "resume/resume-add";
    }

    @RequestMapping(value = "/add")
    public String add(Resume resume){
        logger.info("====== add");
        resumeService.addResume(resume);
        return "redirect:/resume/list";
    }
}